package com.example.wendao.model.db.dao;

import androidx.paging.DataSource;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.example.wendao.model.entity.NewsComment;

@Dao
public interface NewsCommentDao {

    // 插入评论
    @Insert
    void insertForum(NewsComment... newsComments);

    // 查询所有评论
    @Query("SELECT * FROM NewsComment")
    DataSource.Factory<Integer, NewsComment> findAllNewsComments();

    //根据所属论坛或新闻以及论坛新闻标识符查找评论
    @Query("SELECT * FROM newscomment where fatherId =:fatherid and newsorforum =:newsorforum")
    DataSource.Factory<Integer, NewsComment> findAllNewsCommentsByFatherId(int fatherid,int newsorforum);

    //根据所属父评论查找评论
    @Query("select * from newscomment where fatherCommentId = :fathercommentid and newsorforum =:newsorforum")
    DataSource.Factory<Integer, NewsComment> findAllNewsCommentsByFatherCommentId(int fathercommentid,int newsorforum);

    //查找用户新闻下的所有评论 forumId in (:forumids)
    @Query("select * from newscomment where fatherId in (:newsids) and newsorforum = 1")
    DataSource.Factory<Integer, NewsComment> findAllNewsCommentsBynewsids(String newsids);

    //查找用户论坛下的所有评论
    @Query("select * from newscomment where fatherId in (:forumsids) and newsorforum = 2")
    DataSource.Factory<Integer, NewsComment> findAllForumsCommentsBynewsids(String forumsids);



    // 更新新闻评论
    @Update
    void updateNewsComments(NewsComment... newsComments);

    // 删除新闻评论
    @Delete
    void deleteNewsComment(NewsComment... newsComments);
}
